package edu.gyc.hiblog.templates;

import com.github.pagehelper.PageInfo;
import edu.gyc.hiblog.service.PostService;
import edu.gyc.hiblog.vo.PostVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TopPostTemplate extends TemplateDirective {
    @Autowired
    PostService postService;

    @Override
    public String getName() {
        return "posts";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        Integer level = handler.getInteger("level");
        Integer pageNum = handler.getInteger("pageNum",1);
        Integer pageSize = handler.getInteger("size",2);
        Long categoryId = handler.getLong("categoryId");
        log.info("level",level);
        PageInfo<PostVo> postVoPageInfo = postService.paging(pageNum, pageSize,categoryId, null, level, null, "authorName");

        handler.put(RESULTS,postVoPageInfo).render();

    }
}
